package org.example.myleet.rosalind.inod;

public class Solution {
    public static void main(String[] args) {
        Solution solution = new Solution();
//        solution.run(4);
//        solution.run(5);
//        solution.run(6);
//        solution.run(7);
//        solution.run(8);
        solution.run(4290);
    }

    public void run(int n) {
        int leaves = 1, internal = 0;
        for (int i = 1; i < 20; ++i) {
            leaves *= 2;
            if (leaves >= n) {
                int diff = leaves - n;
                internal -= diff;
                System.out.println(internal);
                break;
            }
            internal += leaves;
        }
    }
}
